<?

/***************************************************************************
 Jupiter Content System @ Jupiterportal.com
 Copyright (C) 2005 Cosmin Flavius (highstrike@gmail.com)

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 More Info About The Licence At http://www.gnu.org/copyleft/gpl.html
****************************************************************************/

//-----------------------------------------------------------------
//  Filter Acces Rightes
//-----------------------------------------------------------------

if(isset($is_guest))
{ header("location: $PHP_SELF?i=2"); exit; }

//-----------------------------------------------------------------
//  Get Logged in User's Info
//-----------------------------------------------------------------

$user_info = $db->getLine("SELECT forumposts, lastvisit FROM users WHERE id = '".$db->escape($_SESSION["$security_session"]['id'])."' AND username = '".$db->escape($_SESSION["$security_session"]['username'])."'");

//-----------------------------------------------------------------
//  Count Bans
//-----------------------------------------------------------------

$TotalBansCount = $db->getInfo_countRows("bans");

//-----------------------------------------------------------------
//  Count Forum Topics and Posts
//-----------------------------------------------------------------

$TotalTopicsCount = $db->getInfo_countRows("forum_topics","type != 3");
$TotalPostsCount = $db->getInfo_countRows("forum_replies");

//-----------------------------------------------------------------
//  Calculate the hit averages
//-----------------------------------------------------------------

$days_uptime = intval(abs((((($misc['site_opened'] - time())/60)/60)/24)));

$daily_average = @round(($misc['total_hits']/$days_uptime), 0);
$weekly_average = @round(($misc['total_hits']/($days_uptime/7)), 0);
$monthly_average = @round(($misc['total_hits']/($days_uptime/30)), 0);

//-----------------------------------------------------------------
//  UNIX load
//-----------------------------------------------------------------

if (@file_exists('/proc/loadavg'))
{
	$fh = @fopen('/proc/loadavg', 'r');
	$load_averages = @fread($fh, 64);
	@fclose($fh);

	$load_averages = @explode(' ', $load_averages);
	$server_load = $load_averages[0].' '.$load_averages[1].' '.$load_averages[2];
}
else
	$server_load = $language['HQ server desc8'];

//-----------------------------------------------------------------
//  PHP Accelerator
//-----------------------------------------------------------------

if(function_exists('mmcache')) $php_accelerator = '<a href="http://turck-mmcache.sourceforge.net/" target="_blank">Turck MMCache</a>';
elseif(function_exists('apc_add')) $php_accelerator = '<a href="http://uk.php.net/apc" target="_blank">Alternative PHP Cache</a>';
elseif(function_exists('eaccelerator')) $php_accelerator = '<a href="http://eaccelerator.net/" target="_blank">eAccelerator</a>';
elseif(function_exists('xcache_count')) $php_accelerator = '<a href="http://trac.lighttpd.net/xcache/" target="_blank">XCache</a>';
elseif(function_exists('zend_version')) $php_accelerator = '<a href="http://www.zend.com/en/products/guard/optimizer/" target="_blank">Zend Optimizer</a>';
elseif(isset($_PHPA)) $php_accelerator = '<a href="http://www.php-accelerator.co.uk/" target="_blank">ionCube PHP</a>';
else $php_accelerator = 'N/A';

//-----------------------------------------------------------------
//  Database system version
//-----------------------------------------------------------------

$result = $db->query('SELECT version()');
$db_version = @mysql_result($result, 0);

//-----------------------------------------------------------------
//  Collect some info about MySQL
//-----------------------------------------------------------------

$result = $db->query("SHOW TABLE STATUS FROM `".$db->escape($database_name)."`");
$num_tables = @mysql_num_rows($result);

$total_records = NULL;
$total_size = NULL;
while ($num_tables--)
{
	$status = @mysql_fetch_row($result);
	$total_records += $status[4];
	$total_size += $status[6] + $status[8];
}

$total_size = $total_size / 1024;

if ($total_size > 1024) $total_size = round($total_size / 1024, 2).' MB';
else $total_size = round($total_size, 2).' KB';

//-----------------------------------------------------------------
//  Count PM
//-----------------------------------------------------------------

$new_pm_count = $db->getInfo_countRows("pm","r_user_id = '".$db->escape($_SESSION["$security_session"]['id'])."' AND r_user_user = '".$db->escape($_SESSION["$security_session"]['username'])."' AND r_date = 'unread' AND r_delete = 1");

//-----------------------------------------------------------------
//  Display information
//-----------------------------------------------------------------

?>
<table class="main" cellspacing="1" cellpadding="4">
<tr class="head"><td class="head" colspan="2"><?= $language['HQ user title'] ?></td></tr>
<tr><td class="con1"><?= "{$language['HQ user desc']} <span class='ok'>{$_SESSION["$security_session"]['username']}</span>" ?></td></tr>
<tr><td class="con1"><?= "{$language['HQ user desc2']} <span class='bold'>".find_authorization($_SESSION["$security_session"]['authorization'])."</span>" ?></td></tr>
<tr><td class="con1"><?= "{$language['HQ user desc3']} $new_pm_count {$language['HQ user desc6']}" ?></td></tr>
<tr><td class="con1"><?= "{$language['HQ user desc4']} {$user_info['forumposts']}" ?></td></tr>
<tr><td class="con1"><?= "{$language['HQ user desc5']} "; if(!last_visit($user_info['lastvisit'])) echo "0 {$language['Time Definition Seconds']} {$language['HQ user desc7']}"; else echo last_visit($user_info['lastvisit']) ?></td></tr>
</table>
<? if(isset($is_moderator) || isset($is_administrator) || isset($is_webmaster)){ ?>
<table><tr><td></td></tr></table>

<table class="main" cellspacing="1" cellpadding="4">
<tr class="head"><td class="head"><?= $language['HQ site title'] ?></td></tr>
<tr><td class="con1"><?= "{$language['HQ site desc']} $TotalTopicsCount" ?></td></tr>
<tr><td class="con1"><?= "{$language['HQ site desc2']} $TotalPostsCount" ?></td></tr>
<tr><td class="con1"><?= "{$language['HQ site desc3']} $TotalBansCount" ?></td></tr>
<tr><td class="con1"><?= "{$language['HQ site desc4']} $TotalOnlineCount" ?></td></tr>
<tr><td class="con1"><?= "{$language['HQ site desc5']} {$misc['total_hits']}" ?></td></tr>
<tr><td class="con1"><?= "{$language['HQ site desc6']} {$misc['unique_hits']}" ?></td></tr>
<tr><td class="con1"><?= "{$language['HQ site desc7']} ".($daily_average ? $daily_average : $language['HQ site desc10']) ?></td></tr>
<tr><td class="con1"><?= "{$language['HQ site desc8']} ".($weekly_average ? $weekly_average : $language['HQ site desc10']) ?></td></tr>
<tr><td class="con1"><?= "{$language['HQ site desc9']} ".($monthly_average ? $monthly_average : $language['HQ site desc10']) ?></td></tr>
<tr><td class="con1"><?= "{$language['HQ site desc11']} {$misc['totalonline']}" ?></td></tr>
</table>
<? } if(isset($is_administrator) || isset($is_webmaster)) { ?>
<table><tr><td></td></tr></table>

<table class="main" cellspacing="1" cellpadding="4">
<tr class="head"><td class="head"><?= $language['HQ server title'] ?></td></tr>
<tr><td class="con1"><?= "{$language['HQ server desc']} $server_load ($TotalOnlineCount users online)" ?></td></tr>
<tr><td class="con1"><?= "{$language['HQ server desc2']} PHP_OS" ?></td></tr>
<tr><td class="con1"><?= "{$language['HQ server desc3']} ".phpversion() ?></td></tr>
<tr><td class="con1"><?= "{$language['HQ server desc4']} $php_accelerator" ?></td></tr>
<tr><td class="con1"><?= "{$language['HQ server desc5']} $db_version" ?></td></tr>
<tr><td class="con1"><?= "{$language['HQ server desc6']} $total_records" ?></td></tr>
<tr><td class="con1"><?= "{$language['HQ server desc7']} $total_size" ?></td></tr>
</table>
<? } ?>